import numpy as np
import pandas as pd

ObjV = np.array([[98.227429, 4609.47935, 440.20417],
                 [98.24810234, 4610.97931, 444.90859],
                 [98.22053788, 4571.29855, 439.99963],
                 [98.22053788, 4599.59325, 439.79509],
                 [98.23432011, 4566.42368, 443.91998],
                 [98.23432011, 4615.85418, 440.98824],
                 [98.24810234, 4610.97931, 444.90859],
                 [98.22053788, 4560.73065, 441.36323],
                 [98.24810234, 4614.49058, 444.5336],
                 [98.26877568, 4631.87648, 449.03348],
                 [98.227429, 4570.61675, 441.77231],
                 [98.25499345, 4582.00281, 446.88581],
                 [98.227429, 4577.67338, 440.7837],
                 [98.24810234, 4614.49058, 444.5336],
                 [98.24066332, 4569.25315, 445.31767],
                 [98.22053788, 4599.59325, 439.79509],
                 [98.227429, 4574.16211, 441.15869],
                 [98.25499345, 4620.86541, 445.31767],
                 [98.24810234, 4575.62798, 446.10174],
                 [98.26188456, 4620.18361, 447.09035],
                 [98.227429, 4577.67338, 440.7837],
                 [98.23432011, 4584.04821, 441.56777],
                 [98.23432011, 4605.28628, 442.35184],
                 [98.24121122, 4615.17238, 442.76092],
                 [98.22053788, 4560.73065, 441.36323],
                 [98.27566679, 4643.56935, 450.97661],
                 [98.23432011, 4566.42368, 443.91998],
                 [98.27566679, 4643.56935, 450.97661],
                 [98.24810234, 4572.11671, 446.47673],
                 [98.21364677, 4561.41245, 439.59055],
                 [98.26188456, 4593.69568, 448.82894],
                 [98.23432011, 4569.93495, 443.54499],
                 [98.227429, 4609.47935, 440.20417],
                 [98.23432011, 4573.48031, 442.93137],
                 [98.24810234, 4575.62798, 446.10174],
                 [98.24810234, 4621.54721, 443.54499],
                 [98.23432011, 4605.28628, 442.35184],
                 [98.25499345, 4620.86541, 445.31767],
                 [98.22053788, 4567.78728, 440.37462],
                 [98.24810234, 4614.49058, 444.5336],
                 [98.26188456, 4593.69568, 448.82894],
                 [98.23432011, 4608.79755, 441.97685],
                 [98.24121122, 4572.79851, 444.70405],
                 [98.25499345, 4610.29751, 446.68127],
                 [98.24121122, 4572.79851, 444.70405],
                 [98.23432011, 4573.48031, 442.93137],
                 [98.24810234, 4575.62798, 446.10174],
                 [98.23432011, 4584.04821, 441.56777],
                 [98.25499345, 4613.80878, 446.30628],
                 [98.23432011, 4559.36705, 444.90859],
                 [98.227429, 4560.04885, 443.13591],
                 [98.23432011, 4559.36705, 444.90859],
                 [98.23432011, 4608.79755, 441.97685],
                 [98.22053788, 4571.29855, 439.99963],
                 [98.24121122, 4583.36641, 443.34045],
                 [98.25499345, 4626.18345, 446.47673],
                 [98.24121122, 4576.30978, 444.32906],
                 [98.24121122, 4583.36641, 443.34045],
                 [98.23432011, 4569.93495, 443.54499],
                 [98.24810234, 4575.62798, 446.10174],
                 [98.23432011, 4576.99158, 442.55638],
                 [98.227429, 4605.96808, 440.57916],
                 [98.2825579, 4655.26222, 452.91974],
                 [98.227429, 4570.61675, 441.77231],
                 [98.23432011, 4573.48031, 442.93137],
                 [98.26877568, 4605.38855, 450.77207],
                 [98.25499345, 4610.29751, 446.68127],
                 [98.24121122, 4611.66111, 443.13591],
                 [98.26188456, 4620.18361, 447.09035],
                 [98.24810234, 4582.68461, 445.11313],
                 [98.24121122, 4615.17238, 442.76092],
                 [98.27566679, 4617.08142, 452.7152],
                 [98.25499345, 4582.00281, 446.88581],
                 [98.24121122, 4611.66111, 443.13591],
                 [98.24810234, 4621.54721, 443.54499],
                 [98.23432011, 4612.34291, 441.36323],
                 [98.227429, 4574.16211, 441.15869],
                 [98.24121122, 4622.22901, 441.77231],
                 [98.23432011, 4612.34291, 441.36323],
                 [98.24121122, 4576.30978, 444.32906],
                 [98.26877568, 4605.38855, 450.77207],
                 [98.23432011, 4605.28628, 442.35184],
                 [98.2825579, 4655.26222, 452.91974],
                 [98.227429, 4560.04885, 443.13591],
                 [98.2825579, 4655.26222, 452.91974],
                 [98.26877568, 4631.87648, 449.03348],
                 [98.22053788, 4567.78728, 440.37462],
                 [98.25499345, 4626.18345, 446.47673],
                 [98.25499345, 4613.80878, 446.30628],
                 [98.24810234, 4582.68461, 445.11313],
                 [98.24121122, 4622.22901, 441.77231],
                 [98.23432011, 4584.04821, 441.56777],
                 [98.23432011, 4576.99158, 442.55638],
                 [98.27566679, 4617.08142, 452.7152],
                 [98.227429, 4567.10548, 442.1473],
                 [98.24810234, 4572.11671, 446.47673],
                 [98.24121122, 4565.74188, 445.69266],
                 [98.227429, 4567.10548, 442.1473],
                 [98.23432011, 4573.48031, 442.93137],
                 [98.24121122, 4565.74188, 445.69266]])


def stand_score(x, xmax, xmin):
    print('X: {}'.format(x))
    z = (xmax - x) * 10 / (xmax - xmin)
    return z


def result_format_output(ObjV):
    # ObjV = result['ObjV']
    pqi = ObjV[:, [0]]
    cost = ObjV[:, [1]]
    carbon = ObjV[:, [2]]
    pqi_max = np.max(pqi)
    pqi_min = np.min(pqi)
    cost_max = np.max(cost)
    cost_min = np.min(cost)
    carbon_max = np.max(carbon)
    carbon_min = np.min(carbon)
    print('PQI max: {}, min: {}'.format(pqi_max, pqi_min))
    print('const max: {}, min: {}'.format(cost_max, cost_min))
    print('carbon max: {}, min: {}'.format(carbon_max, carbon_min))
    pqi_score = stand_score(pqi, pqi_max, pqi_min)
    cost_score = stand_score(cost, cost_max, cost_min)
    carbon_score = stand_score(carbon, carbon_max, carbon_min)
    scores = 0.4 * pqi_score + 0.4 * cost_score + 0.2 * carbon_score
    print(scores)
    print(type(scores))

    # df = pd.DataFrame(columns=['养护费用', '标准化分值', '碳排放量', '标准化分值', '路面质量指数', '标准化分值', '总分'])
    data = np.hstack((cost, cost_score, carbon, carbon_score, pqi, pqi_score, scores))
    df = pd.DataFrame(data, columns=['养护费用', '标准化分值', '碳排放量', '标准化分值', '路面质量指数', '标准化分值',
                                     '总分'])
    print(df)
    df.to_csv('outputs/养护方案.csv')


if __name__ == '__main__':
    result_format_output(ObjV)
